package net.cyndeline.components.world

import net.cyndeline.entitySystem.Component
import net.cyndeline.entitySystem.EntityRef
import net.cyndeline.GameMap.LevelMap
import com.escalatesoft.subcut.inject.BindingModule
import com.escalatesoft.subcut.inject.Injectable
import net.cyndeline.GameMap.dataStructure.NullMap

/**
 * Associates an entity with a specific map. Note that in order to
 * exist on the map board state, an entity also needs the Position
 * component.
 */
trait OnMapComponent extends Component {
  def map: LevelMap
  def map_=(newMap: LevelMap)
}

class OnMap(implicit val bindingModule: BindingModule)
extends OnMapComponent with Injectable {
  private var mapp = injectOptional[LevelMap] getOrElse { new NullMap }
  
  override def map = mapp
  override def map_=(map: LevelMap) { mapp = map }
  
  override def copy = {
    val copy = new OnMap()
    copy.map = map
    copy
  }
}